//---------------------------------------------
// IBL
//#ifdef ImageBasedLighting
//  uniform samplerCube IBLDiffuseTexture;
//  uniform samplerCube IBLSpecularTexture;
//#endif

//---------------------------------------------
// Mirror
#if defined (GROUND_MIRRORING)

  vec4 GetGroundMirrorColor(const vec3 iWorldNormal)
  {
  #ifdef MultiviewSinglePass
    ivec3 tsize = vTextureSize(mirrorMapTex, 0);
    vec3 texCoord = vec3(gl_FragCoord.x / float(tsize.x), gl_FragCoord.y / float(tsize.y), float(vGetViewID()));
  #else
    ivec2 tsize = vTextureSize(mirrorMapTex, 0);
    vec2 texCoord = vec2(gl_FragCoord.x / float(tsize.x), gl_FragCoord.y / float(tsize.y));
  #endif

    texCoord.xy *= cb_Ground.u_MirrorScaleFactor;
    texCoord.xy += ComputeMirrorDeviationFromNormal(iWorldNormal);
    return vTexture(mirrorMapTex, texCoord);
  }

  vec4 GetGroundMirrorColor()
  {
  #ifdef MultiviewSinglePass
    ivec3 tsize = vTextureSize(mirrorMapTex, 0);
    vec3 textCoord = vec3(gl_FragCoord.x/float(tsize.x), gl_FragCoord.y/float(tsize.y), float(vGetViewID()));
  #else
    ivec2 tsize = vTextureSize(mirrorMapTex, 0);
    vec2 textCoord = vec2(gl_FragCoord.x/float(tsize.x), gl_FragCoord.y/float(tsize.y));
  #endif

    textCoord.xy *= cb_Ground.u_MirrorScaleFactor;
    return vTexture(mirrorMapTex, textCoord);
  }
#endif 

//---------------------------------------------
// color
#ifndef GLES2Platform
  layout(location = 0) out vec4 fragColor;
  #define FRAGCOLOR fragColor

#if defined WeightedAverage || defined OIT_TAIL_WA
    layout(location = 1) out vec4 fragDepthWA;
#define MRT_1_TAKEN
#endif //WeightedAverage

#ifdef OutputNormalMap
#define FRAGNORMAL fragNormal
#if defined(MRT_1_TAKEN)
    layout(location = 2) out vec4 fragNormal;
#define MRT_2_TAKEN
#else
    layout(location = 1) out vec4 fragNormal;
#define MRT_1_TAKEN
#endif
#endif // OutputNormalMap

#ifdef OutputIBLReflMap
#define FRAGREFLECT fragIBLRefl
#if defined(MRT_2_TAKEN)
    layout(location = 3) out vec4 fragIBLRefl;
#define MRT_3_TAKEN
#elif defined(MRT_1_TAKEN)
    layout(location = 2) out vec4 fragIBLRefl;
#define MRT_2_TAKEN
#else
    layout(location = 1) out vec4 fragIBLRefl;
#define MRT_1_TAKEN
#endif
#endif // OutputIBLReflMap

#ifdef OutputF0RoughMap
#define FRAGMATPROP fragF0Rough
#if defined(MRT_3_TAKEN)
    layout(location = 4) out vec4 fragF0Rough;
#define MRT_4_TAKEN
#elif defined(MRT_2_TAKEN)
    layout(location = 3) out vec4 fragF0Rough;
#define MRT_3_TAKEN
#elif defined(MRT_1_TAKEN)
    layout(location = 2) out vec4 fragF0Rough;
#define MRT_2_TAKEN
#else
    layout(location = 1) out vec4 fragF0Rough;
#define MRT_1_TAKEN
#endif
#endif // OutputF0RoughMap

#ifdef OutputUVMap
#if defined(MRT_4_TAKEN)
    layout(location = 5) out vec2 fragUV;
#define MRT_5_TAKEN
#elif defined(MRT_3_TAKEN)
    layout(location = 4) out vec2 fragUV;
#define MRT_4_TAKEN
#elif defined(MRT_2_TAKEN)
    layout(location = 3) out vec2 fragUV;
#define MRT_3_TAKEN
#elif defined(MRT_1_TAKEN)
    layout(location = 2) out vec2 fragUV;
#define MRT_2_TAKEN
#else
    layout(location = 1) out vec2 fragUV;
#define MRT_1_TAKEN
#endif
#endif

#ifdef OutputWorldPos
#if defined(MRT_5_TAKEN)
    layout(location = 6) out vec4 fragWorldPos;
#define MRT_6_TAKEN
#elif defined(MRT_4_TAKEN)
    layout(location = 5) out vec4 fragWorldPos;
#define MRT_5_TAKEN
#elif defined(MRT_3_TAKEN)
    layout(location = 4) out vec4 fragWorldPos;
#define MRT_4_TAKEN
#elif defined(MRT_2_TAKEN)
    layout(location = 3) out vec4 fragWorldPos;
#define MRT_3_TAKEN
#elif defined(MRT_1_TAKEN)
    layout(location = 2) out vec4 fragWorldPos;
#define MRT_2_TAKEN
#else
    layout(location = 1) out vec4 fragWorldPos;
#define MRT_1_TAKEN
#endif
#endif

#ifdef OutputMotionVectorMap
  #if defined(MRT_6_TAKEN)
    layout(location = 7) out vec2 fragMotionVector;
    #define MRT_7_TAKEN
  #elif defined(MRT_5_TAKEN)
    layout(location = 6) out vec2 fragMotionVector;
    #define MRT_6_TAKEN
  #elif defined(MRT_4_TAKEN)
    layout(location = 5) out vec2 fragMotionVector;
    #define MRT_5_TAKEN
  #elif defined(MRT_3_TAKEN)
    layout(location = 4) out vec2 fragMotionVector;
    #define MRT_4_TAKEN
  #elif defined(MRT_2_TAKEN)
    layout(location = 3) out vec2 fragMotionVector;
    #define MRT_3_TAKEN
  #elif defined(MRT_1_TAKEN)
    layout(location = 2) out vec2 fragMotionVector;
    #define MRT_2_TAKEN
  #else
    layout(location = 1) out vec2 fragMotionVector;
    #define MRT_1_TAKEN
  #endif
#endif // OutputMotionVectorMap

#else
  #define FRAGCOLOR gl_FragColor
#endif
